<!-- 搜索表单 -->
<template>
  <el-form label-width="100px"
           class="ele-form-search"
           ref="form"
           @keyup.enter.native="search"
           @submit.native.prevent>
    <el-row :gutter="15">
      <el-col :lg="6"
              :md="12">
        <el-form-item label="用户名称:">
          <el-input clearable
                    v-model="where.name"
                    placeholder="请输入用户名称" />
        </el-form-item>
      </el-col>

      <el-col :lg="6"
              :md="12">
        <div class="ele-form-actions">
          <el-button type="primary"
                     icon="el-icon-search"
                     class="ele-btn-icon"
                     @click="search">
            查询
          </el-button>

          <el-button @click="reset('form')">重置</el-button>
        </div>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
// import RegionsSelect from '@/components/RegionsSelect/index.vue';
import { getRegionLabel, cityData } from 'ele-admin/packages/utils/regions';
const DEFAULT_WHERE = {
  name: '',

};

export default {
  name: 'RoleSearch',
  components: {

  },
  data () {
    return {
      // 表单数据
      where: { ...DEFAULT_WHERE },
      sumbitForm: {},
      address: ''



    };
  },
  computed: {

    //  code码获取城市标题
    getRegionLabel () {
      return function (params) {
        console.log(cityData);

        return getRegionLabel(params);
      };
    },

  },
  methods: {
    regionsInput (value, nameCode) {
      console.log(value, '==============', nameCode);
      const regionLabel = getRegionLabel(value);
      console.log(regionLabel.join(''))
      this.address = regionLabel.join('');
    },
    /* 搜索 */
    search () {
      for (const key in this.where) {
        if (key == 'dateRange') {
          let startTime = this.where[key]?.[0];
          let endTime = this.where[key]?.[1];
          this.sumbitForm['start_create_time'] =
            startTime == undefined ? '' : startTime;
          this.sumbitForm['end_create_time'] =
            endTime == undefined ? '' : endTime;
        } else if (key == 'associate_addr') {
          this.sumbitForm.associate_addr = this.address;
        } else {
          this.sumbitForm[key] = this.where[key];
        }
      }

      //   console.log(this.sumbitForm)
      this.$emit('search', this.sumbitForm);
    },
    /*  重置 */
    reset (formName) {
      this.$refs[formName].resetFields();

      this.where = {}
      this.sumbitForm = {};

      this.$emit('search', this.sumbitForm);
    }
  }
};
</script>
